// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).
using System.Runtime.Serialization;

using Tierless.Framework.Entities;
using Tierless.Framework.EntityTypes;

namespace Tierless.Framework.Data
{
	/// <summary>
	/// Represents a related entity specifier as part of an entity query.
	/// </summary>
	[DataContract]
	public class RelatedEntitySpecifier
	{
		/// <summary>
		/// Initializes a new instance of the RelatedEntitySpecifier class.
		/// </summary>
		/// <param name="entitySpecifier">An entity specifier instance describing the related entity type.</param>
		/// <param name="columnNames">The relating column names in the main entity type.</param>
		/// <param name="relatedColumnNames">The relating column names in the related entity type.</param>
		public RelatedEntitySpecifier
		(
			EntitySpecifier entitySpecifier,
			string[] columnNames,
			string[] relatedColumnNames
		)
		{
			_entitySpecifier = entitySpecifier;
			_columnNames = columnNames;
			_relatedColumnNames = relatedColumnNames;
		}

		[DataMember]
		private EntitySpecifier _entitySpecifier;

		/// <summary>
		/// Gets an EntitySpecifier defining the related entity type.
		/// </summary>
		public EntitySpecifier EntitySpecifier
		{
			get { return _entitySpecifier; }
		}

		[DataMember]
		private string[] _columnNames;

		/// <summary>
		/// Gets the list of relating columns in the main entity type.
		/// </summary>
		public string[] ColumnNames
		{
			get { return _columnNames; }
		}

		[DataMember]
		private string[] _relatedColumnNames;

		/// <summary>
		/// Gets the list of relating columns in the related entity type.
		/// </summary>
		public string[] RelatedColumnNames
		{
			get { return _relatedColumnNames; }
		}

		/// <summary>
		/// Gets or sets the parent entity specifier.
		/// </summary>
		public EntitySpecifier Parent { get; set; }

		/// <summary>
		/// Gets or sets the entity reference that this related entity specifier resolved to.
		/// </summary>
		public EntityReference Reference { get; set; }
	}
}